<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" th:href="@{/adminlte/layui/css/layui.css}"  media="all"/>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="returnOrder">
    <div class="layui-inline" style="margin-left:0px">销售单号：</div>
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="returnOrderNum" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入销售单号"/>
    </div>
    <div class="layui-inline" style="margin-left: -15px">操作员名称：</div>
    <div class="layui-inline" style="width: 220px;">
        <input class="layui-input"  id="returnOpera" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入操作员名称"/>
    </div>
    起始日期：
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="returnStartDate" autocomplete="off" style="width: 200px;height: 25px" placeholder="请选择起始日期"/>
    </div>
    截止日期：
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="returnEndDate" autocomplete="off" style="width: 190px;height: 25px" placeholder="请选择截止日期"/>
    </div>
    <button class="layui-btn layui-btn-sm" data-type="reload">查询</button>
</div>
<div id="addReturn" style="display: none;">
    <div class="my-form">
        <div class="layui-form-item my-form-item" style="margin-top: 20px;margin-left: -40px">
            <label class="layui-form-label layui-icon"  style="width: 170px;">销售单号:</label>
            <div class="layui-input-inline">
                <input id="returnOrderNum1" type="text" name="returnOrderNum1" autocomplete="off" placeholder="请输入销售单号"
                       class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item my-form-item" style="margin-top: 20px;margin-left: -40px">
            <label class="layui-form-label layui-icon"  style="width: 170px;">退换货类型:</label>
            <div class="layui-input-inline">
             <select id="returnSel"  style="width: 190px;height: 40px" >
                 <option value="">请输入退换货类型</option>
                 <option value="退货">退货</option>
                 <option value="换货">换货</option>
             </select>
            </div>
        </div>
        <div class="layui-form-item my-form-item"  style="margin-left: -40px">
            <label class="layui-form-label layui-icon"  style="width: 170px">退换货原因:</label>
            <div class="layui-input-inline">
                <input id="returnReason" type="text" name="returnReason"  autocomplete="off" placeholder="请输入原因"
                       class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item my-form-item"  style="margin-left: -40px">
            <label class="layui-form-label layui-icon"  style="width: 170px">备注:</label>
            <div class="layui-input-inline">
                <input id="returnMark" type="text" name="returnMark"  autocomplete="off" placeholder="请输入备注"
                       class="layui-input"/>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarReturn">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addReturn" >添加</button>
        <button class="layui-btn layui-btn-sm" lay-event="deleteReturn" >删除</button>
    </div>
</script>
<table class="layui-table" lay-data="{url:'/order/view', page:true, id:'idTestReturn',toolbar:'#toolbarReturn',defaultToolbar:['filter', 'print','exports'] }" lay-filter="demoReturn">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}" ></th>
        <th lay-data="{field:'returnNum', width:180}" >销售单号</th>
        <th lay-data="{field:'returnSel', width:180}" >退换货类型</th>
        <th lay-data="{field:'reason', width:180}" >原因</th>
        <th lay-data="{field:'customerName', width:150}" >客户名称</th>
        <th lay-data="{field:'date',width:150}" >订单日期</th>
        <th lay-data="{field:'projectName',width:150}" >工程名称</th>
        <th lay-data="{field:'productNameOrder',width:150}" >产品名称</th>
        <th lay-data="{field:'productSpecificationsOrder',width:150}" >产品规格</th>
        <th lay-data="{field:'customerPressure',width:150}" >使用压力</th>
        <th lay-data="{field:'opera',width:150}">操作人</th>
        <th lay-data="{field:'operaTime',width:180}" >操作时间</th>
        <th lay-data="{field:'statu',width:180}" >状态</th>
        <th lay-data="{field:'remark',width:180}" >备注</th>
    </tr>
    </thead>
</table>

<script th:src="@{/adminlte/layui/layui.js}" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demoReturn)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(demoReturn)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                /*layer.alert('编辑行：<br/>'+ JSON.stringify(data))*/

            }
        });
        //监听头工具栏事件
        table.on('toolbar(demoReturn)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data//获取选中的数据
                ,deList=[1];
            data.forEach(function (n,i) {
                deList.push(n.ids)
            });
            deList.push(2);
            switch(obj.event){
                case 'addReturn':
                    layer.open({
                        type:1,
                        title:'添加',
                        btnAlign: 'c',
                        area: ['400px', '400px'],
                        content: $("#addReturn"),
                        btn:['保存','取消'],
                        success:function(){
                            top.$('#returnOrderNum1').val("");
                            top.$("#returnReason").val("");
                            top.$("#returnMark").val("");
                            top.$("#returnSel").val("");
                        },
                        yes:function(index,layero){
                            var returnNum =top.$('#returnOrderNum1').val();
                            var reason =top.$("#returnReason").val();
                            var remarks =top.$("#returnMark").val();
                            var returnSel =top.$("#returnSel").val();
                            if (returnNum==""||returnSel==""){
                                layer.msg('请输入销售单号或退换货类型', {
                                    btnAlign: 'c',
                                    time: 3000, //20s后自动关闭
                                    btn: ['确定']
                                });
                            }else {
                                $.ajax({
                                    //几个参数需要注意一下
                                    type: "POST",//方法类型
                                    dataType: "json",//预期服务器返回的数据类型
                                    url: "/order/add" ,//url
                                    data: {returnNum:returnNum,reason:reason,remarks:remarks,returnSel:returnSel},
                                    success: function (result) {
                                        console.log(result);//打印服务端返回的数据(调试用)
                                        if (result.success >0) {

                                            layer.msg('操作成功', {
                                                btnAlign: 'c',
                                                time: 3000, //20s后自动关闭
                                                btn: ['确定']
                                            });
                                            table.reload('idTestReturn');
                                        }else{
                                            layer.msg('操作失败', {
                                                btnAlign: 'c',
                                                time: 3000, //20s后自动关闭
                                                btn: ['确定']
                                            });
                                        }
                                    },
                                    error : function() {
                                        alert("异常！");
                                    }
                                });
                                layer.close(index);
                            }
                        },
                        btn2:function (index) {
                            layer.close(index);
                        }
                    })
                    break;

                case 'deleteReturn':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else {
                        layer.confirm('确定删除',{btn: ['确定', '取消'], title: "提示"},function(index){
                            $.ajax({
                                //几个参数需要注意一下
                                type: "POST",//方法类型
                                dataType: "json",//预期服务器返回的数据类型
                                url: "/order/del" ,//url
                                data: {deList:JSON.stringify(deList)},
                                success: function (result) {
                                    if (result.success>0) {
                                        layer.msg('操作成功', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                        table.reload('idTestReturn')
                                    }else{
                                        layer.msg('操作失败', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }
                                }/*,
                                error : function() {
                                    alert("异常！");
                                }*/
                            });
                            layer.close(index);
                        });
                    }
                    break;
            }
        });
        var $ = layui.$, active = {
            /*     getCheckData: function(){ //获取选中数据
                     var checkStatus = table.checkStatus('idTest')
                         ,data = checkStatus.data;
                     layer.alert(JSON.stringify(data));
                 }
                 ,getCheckLength: function(){ //获取选中数目
                     var checkStatus = table.checkStatus('idTest')
                         ,data = checkStatus.data;
                     layer.msg('选中了：'+ data.length + ' 个');
                 }
                 ,isAll: function(){ //验证是否全选
                     var checkStatus = table.checkStatus('idTest');
                     layer.msg(checkStatus.isAll ? '全选': '未全选')
                 }
                 ,*/
            reload:function () {
                var saleNum = $("#returnOrderNum").val();
                var operator = $("#returnOpera").val();
                var startDate = $("#returnStartDate").val();
                var endDate = $("#returnEndDate").val();
                table.reload('idTestReturn',{
                    url:'/order/findSome',
                    where:{saleNum:saleNum,operator:operator,startDate:startDate,endDate:endDate}  ,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })

            }

        };
        $('.returnOrder .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#returnStartDate' //指定元素
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#returnEndDate' //指定元素
            ,type: 'datetime'
        });
    });
    var unSelected = "#999";
    var selected = "#333";
    $(function () {
        $("select").css("color", unSelected);
        $("option").css("color", selected);
        $("select").change(function () {
            var selItem = $(this).val();
            if (selItem == $(this).find('option:first').val()) {
                $(this).css("color", unSelected);
            } else {
                $(this).css("color", selected);
            }
        });
    })
</script>

</body>
</html>